//// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
//package com.linqingying.gitcode.pullrequest.data.service
//
//import com.intellij.collaboration.async.CompletableFutureUtil.submitIOTask
//import com.intellij.diff.util.Side
//import com.intellij.openapi.diagnostic.logger
//import com.intellij.openapi.progress.ProgressIndicator
//import com.intellij.openapi.progress.ProgressManager
//import com.linqingying.gitcode.api.GCGQLRequests
//import com.linqingying.gitcode.api.GCRepositoryCoordinates
//import com.linqingying.gitcode.api.GitCodeApiRequestExecutor
//import com.linqingying.gitcode.api.data.GCPullRequestReviewEvent
//import com.linqingying.gitcode.api.data.GCRepositoryPermissionLevel
//import com.linqingying.gitcode.api.data.pullrequest.GCPullRequestPendingReviewDTO
//import com.linqingying.gitcode.api.data.pullrequest.GCPullRequestReview
//import com.linqingying.gitcode.api.data.pullrequest.GCPullRequestReviewComment
//import com.linqingying.gitcode.api.data.pullrequest.GCPullRequestReviewThread
//import com.linqingying.gitcode.api.data.request.GCPullRequestDraftReviewThread
//import com.linqingying.gitcode.api.util.SimpleGCGQLPagesLoader
//import com.linqingying.gitcode.pullrequest.data.GCPRIdentifier
//import com.linqingying.gitcode.pullrequest.data.service.GCServiceUtil.logError
//import java.util.concurrent.CompletableFuture
//
//class GCPRReviewServiceImpl(private val progressManager: ProgressManager,
//                            private val securityService: GCPRSecurityService,
//                            private val requestExecutor: GitCodeApiRequestExecutor,
//                            private val repository: GCRepositoryCoordinates) : GCPRReviewService {
//
//  override fun canComment() = securityService.currentUserHasPermissionLevel(GCRepositoryPermissionLevel.READ)
//
//  override fun loadPendingReview(progressIndicator: ProgressIndicator, pullRequestId: GCPRIdentifier) =
//    progressManager.submitIOTask(progressIndicator) {
//      requestExecutor.execute(progressIndicator,
//                              GCGQLRequests.PullRequest.Review.pendingReviews(repository.serverPath, pullRequestId.id)).nodes.singleOrNull()
//    }.logError(LOG, "Error occurred while loading pending review")
//
//  override fun loadReviewThreads(progressIndicator: ProgressIndicator, pullRequestId: GCPRIdentifier) =
//    progressManager.submitIOTask(progressIndicator) {
//      SimpleGCGQLPagesLoader(requestExecutor, { p ->
//        GCGQLRequests.PullRequest.reviewThreads(repository, pullRequestId.number, p)
//      }).loadAll(it)
//    }.logError(LOG, "Error occurred while loading review threads")
//
//  override fun createReview(progressIndicator: ProgressIndicator,
//                            pullRequestId: GCPRIdentifier,
//                            event: GCPullRequestReviewEvent?,
//                            body: String?,
//                            commitSha: String?,
//                            threads: List<GCPullRequestDraftReviewThread>?): CompletableFuture<GCPullRequestPendingReviewDTO> =
//    progressManager.submitIOTask(progressIndicator) {
//      requestExecutor.execute(progressIndicator,
//                              GCGQLRequests.PullRequest.Review.create(repository.serverPath, pullRequestId.id, event, body,
//                                                                      commitSha, threads))
//    }.logError(LOG, "Error occurred while creating review")
//
//  override fun submitReview(progressIndicator: ProgressIndicator,
//                            pullRequestId: GCPRIdentifier,
//                            reviewId: String,
//                            event: GCPullRequestReviewEvent,
//                            body: String?): CompletableFuture<out Any?> =
//    progressManager.submitIOTask(progressIndicator) {
//      requestExecutor.execute(progressIndicator,
//                              GCGQLRequests.PullRequest.Review.submit(repository.serverPath, reviewId, event, body))
//    }.logError(LOG, "Error occurred while submitting review")
//
//  override fun updateReviewBody(progressIndicator: ProgressIndicator,
//                                reviewId: String,
//                                newText: String): CompletableFuture<GCPullRequestReview> =
//    progressManager.submitIOTask(progressIndicator) {
//      requestExecutor.execute(progressIndicator,
//                              GCGQLRequests.PullRequest.Review.updateBody(repository.serverPath, reviewId, newText))
//    }.logError(LOG, "Error occurred while updating review")
//
//  override fun deleteReview(progressIndicator: ProgressIndicator,
//                            pullRequestId: GCPRIdentifier,
//                            reviewId: String): CompletableFuture<out Any?> =
//    progressManager.submitIOTask(progressIndicator) {
//      requestExecutor.execute(progressIndicator,
//                              GCGQLRequests.PullRequest.Review.delete(repository.serverPath, reviewId))
//    }.logError(LOG, "Error occurred while deleting review")
//
//  override fun addComment(progressIndicator: ProgressIndicator,
//                          pullRequestId: GCPRIdentifier,
//                          reviewId: String,
//                          replyToCommentId: String,
//                          body: String): CompletableFuture<GCPullRequestReviewComment> =
//    progressManager.submitIOTask(progressIndicator) {
//      requestExecutor.execute(
//        it,
//        GCGQLRequests.PullRequest.Review.addComment(repository.serverPath,
//                                                    reviewId,
//                                                    replyToCommentId,
//                                                    body))
//    }.logError(LOG, "Error occurred while adding review thread reply")
//
//  override fun addComment(progressIndicator: ProgressIndicator, reviewId: String,
//                          body: String, commitSha: String, fileName: String, diffLine: Int)
//    : CompletableFuture<GCPullRequestReviewComment> =
//    progressManager.submitIOTask(progressIndicator) {
//      requestExecutor.execute(progressIndicator,
//                              GCGQLRequests.PullRequest.Review.addComment(repository.serverPath,
//                                                                          reviewId,
//                                                                          body, commitSha, fileName,
//                                                                          diffLine))
//    }.logError(LOG, "Error occurred while adding review comment")
//
//  override fun deleteComment(progressIndicator: ProgressIndicator, pullRequestId: GCPRIdentifier, commentId: String) =
//    progressManager.submitIOTask(progressIndicator) {
//      requestExecutor.execute(it, GCGQLRequests.PullRequest.Review.deleteComment(repository.serverPath, commentId))
//    }.logError(LOG, "Error occurred while deleting review comment")
//
//  override fun updateComment(progressIndicator: ProgressIndicator, pullRequestId: GCPRIdentifier, commentId: String, newText: String) =
//    progressManager.submitIOTask(progressIndicator) {
//      requestExecutor.execute(it, GCGQLRequests.PullRequest.Review.updateComment(repository.serverPath, commentId, newText))
//    }.logError(LOG, "Error occurred while updating review comment")
//
//  override fun addThread(progressIndicator: ProgressIndicator, reviewId: String, body: String,
//                         line: Int, side: Side, startLine: Int, fileName: String): CompletableFuture<GCPullRequestReviewThread> =
//    progressManager.submitIOTask(progressIndicator) {
//      requestExecutor.execute(it, GCGQLRequests.PullRequest.Review.addThread(repository.serverPath, reviewId, body, line, side, startLine,
//                                                                             fileName))
//    }.logError(LOG, "Error occurred while adding review thread")
//
//  override fun resolveThread(progressIndicator: ProgressIndicator,
//                             pullRequestId: GCPRIdentifier,
//                             id: String): CompletableFuture<GCPullRequestReviewThread> =
//    progressManager.submitIOTask(progressIndicator) {
//      requestExecutor.execute(it, GCGQLRequests.PullRequest.Review.resolveThread(repository.serverPath, id))
//    }.logError(LOG, "Error occurred while resolving review thread")
//
//  override fun unresolveThread(progressIndicator: ProgressIndicator,
//                               pullRequestId: GCPRIdentifier,
//                               id: String): CompletableFuture<GCPullRequestReviewThread> =
//    progressManager.submitIOTask(progressIndicator) {
//      requestExecutor.execute(it, GCGQLRequests.PullRequest.Review.unresolveThread(repository.serverPath, id))
//    }.logError(LOG, "Error occurred while unresolving review thread")
//
//  companion object {
//    private val LOG = logger<GCPRReviewService>()
//  }
//}
